﻿@{
    ViewBag.Title = "Test_questions";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}



@section head{
    <link href="~/Scripts/bower_components/jPages/css/jPages.css" rel="stylesheet"/>
    <link href="~/Scripts/bower_components/jPages/css/animate.css" rel="stylesheet"/>
    <style>
        .edit, .editer { width: 200px; }

        .table-no { border-left: 30px; }

        .am-u-sm-10 {
            padding-left: 5px;
            padding-top: 10px;
        }

        .am-form { margin-top: 30px; }
    </style>
}

<div class="am-cf am-padding">
    <div class="am-fl am-cf">
        <strong class="am-text-primary am-text-lg" id="">编辑试题</strong> / <small>@ViewBag.test</small>
    </div>
</div>

<div class="am-g">
    <div class="am-u-sm-12">
        <form class="am-form">
            <table class="am-table am-table-striped am-table-hover table-main" id="table">
                <thead>
                <tr>
                    <th class="table-date">题目</th>
                    <th class="table-set">操作</th>
                </tr>
                </thead>
                <tbody id="itemContainer">
                @if (ViewBag.count == 0)
                {
                        @*@: 无信息！*@
                }
                else
                {
                    var i = 1;
                    foreach (var Tempx in ViewBag.list)
                    {
                        <tr id="@Tempx.Id">
                            <td hidden="hidden" class="ider"> @Tempx.Id</td>
                            <td class=" nameer">
                                @Tempx.Question1
                            </td>
                            <td>
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a value="0" onclick="Addclick(@Tempx.Id)" id="button_@Tempx.Id" class="am-btn am-btn-default am-btn-xs"><span class="am-icon-copy"></span> 添加</a>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        i++;
                    }
                }
                </tbody>
            </table>
            <div class="am-cf">
                共 @ViewBag.count 条记录
                <div class="am-fr">
                    <div class="holder am-pagination"></div>
                </div>
            </div>
            <hr/>
            <p id="xxx">注：哇哈哈哈哈哈哈哈</p>
        </form>


    </div>
</div>


@foreach (var x in ViewBag.added)
{
    <div class="add" value="@x.Id" style="display: none">@x.Id</div>
}

@section scripts{


    <script src="~/Scripts/Other/jquery.editable-1.3.3.js"></script>
    <script src="~/Scripts/Other/jpages.js"></script>
    <script src="~/Scripts/Other/jquery.tablesorter.js"></script>

    <script>
        $(function() {
            var x = $(".add");
            x.each(function() {
                var but = $("#button_" + $(this).text());
                but.addClass("am-active").html("已添加");
                but.attr("value", 1);
            });

        });

        function Addclick(id) {
            var but = $("#button_" + id);
            if (but.attr("value") == "0") {
                $.ajax({
                    type: "post",
                    url: '/Admin/manage/Test_addquestions',
                    data: {
                        testid: @Model,
                        questid: id
                    },
                    success: function(r) {
                        if (r == 1) {
                            but.addClass("am-active").html("已添加");
                            but.attr("value", 1);
                        }
                    }
                });
            } else {
                {
                    $.ajax({
                        type: "post",
                        url: '/Admin/manage/Test_delquestions',
                        data: {
                            testid: @Model,
                            questid: id
                        },
                        success: function(res) {
                            if (res == 1) {
                                but.removeClass("am-active").html("<span class='am-icon-copy'></span> 添加");
                                but.attr("value", 0);
                            }
                        }
                    });

                }
            };
        };


        $("#addbutton").click(function() { window.location.href = "/Admin/questions/GeyAll"; });

        $(function() {
            $("#addform").hide();
            $("#table").tablesorter({ sortList: [[1, 0]] });
            $("div.holder").jPages({
                containerID: "itemContainer",
                perPage: 15
            });


            $(".edit").editable({
                onSubmit: function() {
                    var ider = this.parent().find(".ider").text();
                    var nameer = this.parent().find(".nameer").text();
                    var timeer = this.parent().find(".timeer").text();
                    $.ajax({
                        type: "post",
                        url: '/admin/manage/TestUpdate',
                        data: {
                            id: ider,
                            name: nameer,
                            time: timeer
                        }
                    });
                }
            });


        });

    </script>


}